package hl.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;

import hl.pageModel.DataGrid;
import hl.pageModel.Json;
import hl.pageModel.Place;
import hl.pageModel.Salary;
import hl.service.SalaryService;

@Namespace("/")
@Action(value = "salaryAction")
public class SalaryAction extends BaseAction implements ModelDriven<Salary> {
	Salary salary = new Salary();

	private SalaryService salaryService;

	@Override
	public Salary getModel() {
		return salary;
	}

	public SalaryService getSalaryService() {
		return salaryService;
	}

	@Autowired
	public void setSalaryService(SalaryService salaryService) {
		this.salaryService = salaryService;
	}

	public void getDatagrid() {
		DataGrid d = salaryService.getDatagrid(salary);
		super.writeJson(d);
	}
	
	public void add() {
		Json j = new Json();
		try {
			salaryService.save(salary);
			j.setSuccess(true);
			j.setMsg("增加成功");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}
}
